package com.wiki.KBS.Controller;

import com.wiki.KBS.request.EbookReq;
import com.wiki.KBS.request.EbookSaveReq;
import com.wiki.KBS.response.CommonResp;
import com.wiki.KBS.response.EbookQueryResp;
import com.wiki.KBS.response.PageResp;
import com.wiki.KBS.services.EbookService;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/ebook")
public class EbookController {

    @Autowired
    private EbookService ebookService;

    @RequestMapping("/list")
    public CommonResp ebookList(@Valid EbookReq req){
        CommonResp<PageResp<EbookQueryResp>> resp = new CommonResp<>();
        PageResp<EbookQueryResp> ebooks = ebookService.ebookList(req);
        resp.setMessage("ebook数据获取成功！");
        resp.setContent(ebooks);
        return resp;
    }

    @PostMapping("/save")
    public CommonResp save(@Valid @RequestBody EbookSaveReq req){
        CommonResp resp = new CommonResp<>();
        ebookService.save(req);
        return resp;
    }

    @DeleteMapping("/delete/{id}")
    public CommonResp delete(@PathVariable Long id){
        CommonResp resp = new CommonResp<>();
        ebookService.delete(id);
        return resp;
    }
}
